package com.fansea.util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class SendMsg {
    public static void send(String userid ,String text){
        try {
            Thread.sleep(500);
            HttpRequestUtil.doGet("http://127.0.0.1:26666/sendmsg?touser="+userid+"&msg="+URLEncoder.encode(text, "UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
//        return JSONStringHandleUtil.getStats(wordJson,"content");
    }
    public static void sendImg(String userid ,String path){
        try {
            HttpRequestUtil.doGet("http://127.0.0.1:26666/sendimage?touser="+userid+"&path="+ URLEncoder.encode(path, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
//        return JSONStringHandleUtil.getStats(wordJson,"content");
    }

    public static void send3(String userid ,String text ,String wxid){
        try {
            HttpRequestUtil.doGet("http://127.0.0.1:26666/sendatmsg?touser="+userid+"&msg="+text+"&atwxid="+wxid);
//        return JSONStringHandleUtil.getStats(wordJson,"content");
            //请求头
            Map<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type","application/json");

            JSONObject myJsonObject = new JSONObject();
            HttpResponse httpResponse = AliHttpUtils.doGet("http://127.0.0.1:26666/", "/sendatmsg?touser="+userid+"&msg="+text+"&atwxid="+wxid, "GET", headers, new HashMap<>());
//        String weather = HttpRequestUtil.doGet("https://restapi.amap.com/v3/weather/weatherInfo?key="+keyencode+"&city="+encode);
            //获取气温，天气状况
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public static void sendPost(String userid ,String text){
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("touser",userid);
        hashMap.put("msg",text);
        HttpRequestUtil.doPost("http://127.0.0.1:26666/post_sendmsg", "json="+JSON.toJSONString(hashMap));
//        return JSONStringHandleUtil.getStats(wordJson,"content");
    }




//    url = "http://127.0.0.1:26666/post_sendmsg"
//    data = {
//        "touser": "filehelper",
//                "msg": "测试消息2"
//    }
//
//requests.post(url, json=data)






//            url = "http://127.0.0.1:26666/sendatmsg"
//    data = {
//        "touser": "11111111111@chatroom",
//                "msg": "@昵称 222222",
//                "atwxid": "被@人的wxid"
//    }
//    headers = {
//        "content-type": "application/json"
//    }
//    print(requests.get(url, params=data).json())


//    import requests
//
//            url = "http://127.0.0.1:26666/sendimage"
//    params = {
//        "touser": "filehelper",
//                "path": r"C:\Users\Administrator\Pictures\图片1.jpg"
//    }
//
//requests.get(url, params=params)


    public static void main(String[] args) {

        send("","");
    }
}
